package com.haibei.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.common.cache.SimpleImgLoaderLru;
import com.haibei.R;
import com.haibei.adapter.bean.Topic;

public class TopicAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<Topic> mArrayListDataList;

	public TopicAdapter(Activity activity, ArrayList<Topic> datas) {
		this.activity = activity;
		this.mArrayListDataList = datas;
	}

	@Override
	public int getCount() {
		return mArrayListDataList.size();
	}

	@Override
	public Object getItem(int position) {
		return mArrayListDataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vl;
		if (null == convertView) {
			convertView = View.inflate(activity, R.layout.item_topic, null);
			vl = new ViewHolder();
			vl.textViewTitle = (TextView) convertView.findViewById(R.id.textViewTitle);
			vl.textLead = (TextView) convertView.findViewById(R.id.textViewLead);
			vl.textViewComments = (TextView) convertView.findViewById(R.id.textViewCommentCount);
			vl.textPeroid = (TextView) convertView.findViewById(R.id.textViewPeriod);
			vl.imageViewCover = (ImageView) convertView.findViewById(R.id.imageViewImg);
			convertView.setTag(vl);
		} else {
			vl = (ViewHolder) convertView.getTag();
		}
		Topic topic = mArrayListDataList.get(position);
		vl.textViewTitle.setText(topic.getTitle());
		vl.textLead.setText(topic.getLead());
		vl.textViewComments.setText(topic.getConmentCount() + "评论");
		vl.textPeroid.setText("第" + topic.getPeriod() + "期");
		// SimpleImageLoader.display(vl.imageViewUrl,
		// consult.getCoverImg(),R.drawable.bg_default_consult);
		// ImageManagerLru.from(activity).displayImage(vl.imageViewCover,
		// topic.getCoverImg(), R.drawable.bg_default_consult);
		SimpleImgLoaderLru.from(activity).displayImage(vl.imageViewCover, topic.getCoverImg(), R.drawable.bg_default_consult);
		return convertView;
	}

	class ViewHolder {
		TextView textViewTitle;
		TextView textLead;
		TextView textViewComments;
		TextView textPeroid;
		ImageView imageViewCover;
	}

}
